<template>
  <div class="category">
    <!-- 导航栏 -->
    <nav-bar class="category-nav">
      <div slot="center">分类</div>
    </nav-bar>

    <!-- 滑动插件 -->
    <scroll class=" content" ref="scroll">
      <!-- 左侧分类栏 -->
      <type :categoryList="categoryList" @getMaitkey="getMaitkey" />
    </scroll>
    <!-- 滑动插件 -->
    <scroll class="content2" ref="scroll">
      <!-- 实列展示 -->
      <type-list :subCategory="subCategory" />
    </scroll>

  </div>
</template>

<script>
import NavBar from "components/common/navbar/NavBar"
import Scroll from "components/common/scroll/Scroll";

import Type from './childComps/Type';
import TypeList from './childComps/TypeList'

import { getCategory, getSubcategory, getSubcatDetail } from "network/category";

export default {
  name: "Category",
  components: {
    NavBar,
    Type,
    Scroll,
    TypeList
  },
  data () {
    return {
      categoryList: [],
      maitkey: '3627',
      subCategory: []
    };
  },
  created () {
    // 调用请求分类数据
    this.getCategory();
  },
  mounted () {
    this.getSubcategory(this.maitkey)
    // this.getSubcatDetail('50003','衬衫')
  },
  methods: {
    // type子组件传递的值
    getMaitkey (maitkey) {
      this.maitkey = maitkey
      // console.log(maitkey);
      this.getSubcategory(this.maitkey)
    },
    /**
     * 网络请求相关的方法
     */
    getCategory () {
      getCategory().then(res => {
        // console.log(res.data.category.list);
        this.categoryList = res.data.category.list;
      });
    },
    getSubcategory (maitkey) {
      getSubcategory(maitkey).then(res => {
        console.log(res);
        console.log(res.data.list);
        this.subCategory = res.data.list
      })
    },
    getSubcatDetail(miniWallkey,type){
      getSubcatDetail(miniWallkey,type).then(res => {
        console.log(res);
      })      
    }
  }
};
</script>

<style scoped>
.category {
  height: 100vh;
  /* vertical-align: bottom; */
  vertical-align: top;
}
.category-nav {
  background-color: var(--color-tint);
  color: white;
}
.content {
  display: inline-block;
  width: 100px;
  height: calc(100% - 44px - 49px);
  overflow: hidden;
}
.content2 {
  display: inline-block;
  width: 260px;
  height: calc(100% - 44px - 49px);
  overflow: hidden;
}
</style>
